#include "traininfo.h"
/*
 * Date:        2022/11/22
 * Name:        王宇轩
 * Student ID:  20301142
 * Description: 这个类用于记录一趟车次的经停站、起止时间、对应的票余量和价格，
 *              以及提供一些便利的函数
*/
TrainInfo::TrainInfo()
{
    infoNum=0;
}

//******************Get*********************
QString TrainInfo::getTrainNum(int index){
    if(index<0||index>trainNumList.length()-1){
        return "";
    }
    return trainNumList[index];
}

QString TrainInfo::getStartStation(int index){
    if(index<0||index>startStationList.length()-1){
        return "";
    }
    return startStationList[index];
}
QString TrainInfo::getEndStation(int index){
    if(index<0||index>endStationList.length()-1){
        return "";
    }
    return endStationList[index];

}

QString TrainInfo::getStartTime(int index){
    if(index<0||index>startTimeList.length()-1){
        return "";
    }
    return startTimeList[index];
}
QString TrainInfo::getEndTime(int index){
    if(index<0||index>endTimeList.length()-1){
        return "";
    }
    return endTimeList[index];
}
int TrainInfo::getLeftTickets(int index){
    if(index<0||index>leftTicketsList.length()-1){
        return 0;
    }
    return leftTicketsList[index];
}
int TrainInfo::getPrice(int index){
    if(index<0||index>priceList.length()-1){
        return 0;
    }
    return priceList[index];
}

void TrainInfo::setLeftTickets(int index, int value)
{
    if(value<0){
        return;
    }
    if(index<0||index>leftTicketsList.length()-1){
        return;
    }
    leftTicketsList[index]=value;
}

//******************Set*********************
void TrainInfo::addTrainNum(QString temp){
    trainNumList.append(temp);
}
void TrainInfo::addStartStation(QString temp){
    startStationList.append(temp);
}
void TrainInfo::addEndStation(QString temp){
    endStationList.append(temp);
}
void TrainInfo::addStartTime(QString temp){
    startTimeList.append(temp);
}
void TrainInfo::addEndTime(QString temp){
    endTimeList.append(temp);
}
void TrainInfo::addLeftTickets(int temp){
    leftTicketsList.append(temp);
}
void TrainInfo::addPrice(int temp){
    priceList.append(temp);
}

void TrainInfo::addItems(QVector<QString> items)
{
    for(int i=0;i<items.length();i++){

    }
}

// 清空上一次存储的班次信息
void TrainInfo::clearAllItems()
{
    trainNumList.clear();
    startStationList.clear();
    endStationList.clear();
    startTimeList.clear();
    endTimeList.clear();
    leftTicketsList.clear();
    priceList.clear();
    infoNum=0;
}

